package com.example.binpacking.service.Impl;

import com.example.binpacking.mapper.UserMapper;
import com.example.binpacking.model.User;
import com.example.binpacking.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    //登录
    @Override
    public String loginService(String uname, String pwd) {
        User user = userMapper.searchByUname(uname);
        if (user != null) {
            if (pwd.equals(user.getPassword())) {
                return "SUCCESS";
            } else {
                return "密码错误";
            }
        }
        return "此用户不存在";

    }

    //注册
    @Override
    public String registerService(User user) {
        User userE = userMapper.searchByUname(user.getUsername());
        if (userE == null) {
            if ("".equals(user.getPassword())) {
                return "请输入密码";
            } else if ("".equals(user.getUsername())) {
                return "请输入用户昵称";
            } else {
                userMapper.insert(user);
                return "SUCCESS";
            }
        }
        return "用户已存在";
    }
}
